package com.neuedu.mblog.service;

import com.neuedu.mblog.dao.ShiroRoleDao;
import com.neuedu.mblog.dao.ShiroRoleDao;
import com.neuedu.mblog.entiry.ShiroRole;

import javax.management.relation.Role;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;

/**
 * 项目：mblog_java4
 * 创建时间：  2021-12-29   9:21
 * 作者 :jshand
 * 描述 :
 */
public class RoleService {
    private ShiroRoleDao roleDao = new ShiroRoleDao();


    /**
     * 查询集合不分页
     * @param request
     * @return
     */
    public List<ShiroRole> selectList(HttpServletRequest request) throws SQLException {
        //
        String sql = " SELECT   id,   description ,  name ,   status FROM  shiro_role ";
        return roleDao.selectList(sql ,null);
    }


    /**
     * 修改前查询数据
     * @param request
     * @return
     * @throws SQLException
     */
    public ShiroRole selectById(HttpServletRequest request) throws SQLException {
        String id = request.getParameter("id");
        return roleDao.selectById(Integer.parseInt(id));
    }

    public boolean update(HttpServletRequest request) throws SQLException {

        ShiroRole shiroRole = new ShiroRole();
        shiroRole.setId(Integer.parseInt(request.getParameter("id")));
        shiroRole.setName(request.getParameter("name"));
        shiroRole.setDescription(request.getParameter("description"));
        shiroRole.setStatus(Integer.parseInt(request.getParameter("status")));



        return roleDao.update(shiroRole) >0;
    }

    public boolean save(HttpServletRequest request) throws SQLException {
        ShiroRole shiroRole = new ShiroRole();

//        shiroRole.setId(Integer.parseInt(request.getParameter("id")));
        shiroRole.setName(request.getParameter("name"));
        shiroRole.setDescription(request.getParameter("description"));
        shiroRole.setStatus(Integer.parseInt(request.getParameter("status")));

        return roleDao.save(shiroRole) >0;
    }

    public boolean deleteById(HttpServletRequest request) throws SQLException {
        String id = request.getParameter("id");
        return roleDao.delete(Integer.parseInt(id))>0;
    }
}
